﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Threading.Tasks;
using CoreShop.Model;
using CoreShop.Repository;
using SqlSugar;
namespace CoreShop.Services
{
    /// <summary>
    /// 接口实现
    /// </summary>
    public class corecmsuserintegralrulesServices : Repository<corecmsuserintegralrules>, IcorecmsuserintegralrulesServices
    {
        public bool InsertAsync(corecmsuserintegralrules entity)
        {
            return base.Change<corecmsuserintegralrules>().Insert(entity);
        }
        public bool InsertOrUpdate(List<corecmsuserintegralrules> entity)
        {
            return base.InsertOrUpdate(entity);
        }
        /// <summary>
        /// 重写异步更新方法
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateAsync(corecmsuserintegralrules entity)
        {
            return base.Change<corecmsuserintegralrules>().Update(a => new corecmsuserintegralrules()
            {
                corpId = entity.corpId,
                storeId = entity.storeId,
                enableIntegral = entity.enableIntegral,
                isFoodIntegral = entity.isFoodIntegral,
                consumeIntegral = entity.consumeIntegral,
                specialIntegral = entity.specialIntegral,
                integralToCash = entity.integralToCash,
                parentIntegral = entity.parentIntegral,
                giftConsumRuleType = entity.giftConsumRuleType,
                giftproportion = entity.giftproportion,
                rechargeProportion = entity.rechargeProportion,
                modifyTime = entity.modifyTime
            }, a => a.id == entity.id);
        }

        /// <summary>
        /// 重写异步更新方法
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateAsync(List<corecmsuserintegralrules> entity)
        {
            bool returnKey = true;
            foreach (var item in entity)
            {
                returnKey = base.Change<corecmsuserintegralrules>().Update(a => new corecmsuserintegralrules()
                {
                    corpId = item.corpId,
                    storeId = item.storeId,
                    enableIntegral = item.enableIntegral,
                    isFoodIntegral = item.isFoodIntegral,
                    consumeIntegral = item.consumeIntegral,
                    specialIntegral = item.specialIntegral,
                    integralToCash = item.integralToCash,
                    parentIntegral = item.parentIntegral,
                    giftConsumRuleType = item.giftConsumRuleType,
                    giftproportion = item.giftproportion,
                    rechargeProportion = item.rechargeProportion,
                    modifyTime = item.modifyTime
                }, a => a.id == item.id);
            }
            return returnKey;
        }

        #region 获取缓存的所有数据==========================================================

        /// <summary>
        /// 获取缓存的所有数据
        /// </summary>
        /// <returns></returns>
        public List<corecmsuserintegralrules> GetCaChe()
        {
            return base.GetList();
        }

        #endregion
                

    }
}
